<template>
  <router-link
      :to="to"
      class="sidebar-btn"
      :class="{ active: isActive }"
  >
    <div class="icon-wrapper">
      <span class="circle" v-if="isActive"/>
      <img class="icon" :src="icon" alt="icon"/>
    </div>
    <div class="label">{{ label }}</div>
  </router-link>
</template>

<script setup>
import {useRoute} from 'vue-router'
import {computed} from 'vue'

const props = defineProps({
  to: String,
  icon: String,
  label: String
})

const route = useRoute()
const isActive = computed(() => route.path === props.to)
</script>

<style scoped>
.sidebar-btn {
  width: 72px;
  height: calc((100vh - 20px - 10px - 1px - 10px) / 4);
  min-height: 80px;
  max-height: 250px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px auto;
  background: none;
  text-decoration: none;
  transition: background 0.2s;
  position: relative;
}

.sidebar-btn.active {
  background: rgba(220, 220, 220, 0.15);
}

.sidebar-btn:not(.active):hover {
  background: rgba(220, 220, 220, 0.15);
  cursor: pointer;
}

.icon-wrapper {
  position: relative;
  width: 48px;
  height: 48px;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.circle {
  position: absolute;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(60, 160, 190, 0.6);
  top: 0;
  left: 0;
  z-index: 1;
}

.icon {
  width: 28px;
  height: 28px;
  z-index: 2;
  position: relative;
  display: block;
  margin: 0 auto;
}

.label {
  color: #fff;
  font-size: 15px;
  text-align: center;
  z-index: 2;
  user-select: none;
}

.sidebar-btn .icon {
  filter: grayscale(1) brightness(0.85);
}

.sidebar-btn .label {
  color: #e0e0e0;
}

.sidebar-btn.active .icon {
  filter: none;
}

.sidebar-btn.active .label {
  color: #FFFFFF;
}
</style>